/*
 * processor.h
 *
 *  Created on: 05/06/2011
 *      Author: George Ferreira
 */

#ifndef PROCESSOR_H_
#define PROCESSOR_H_

#include <fstream>
#include <string>

#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/ip_icmp.h>

#include <net/ethernet.h>
#include <arpa/inet.h>
#include <pcap.h>
#include <semaphore.h>
#include <iomanip>

#include "ethernetprocess.h"
#include "network.h"
#include "host.h"
#include "defines.h"
#include "session.h"
#include "adjacencia.h"
#include "types.h"
#include "ipprocess.h"

#include <iostream>
#include <cstdlib>
#include "icmpsessionmanager.h"
#include "tcpsession.h"
#include "tcpsessionmanager.h"

#include "udpsessionmanager.h"

#include "icmperrorsessionmanager.h"
using namespace std;


class Processor {

//		Here starts our entire hard job
public:
	static void logadj(string ip_s, string ip_d){
		ofstream log;
		log.open("/var/www/dunadan/adj.dn", ios_base::app);

		if ( !log.is_open()){
			cout << "Erro ao abrir arquivo '/var/www/dunadan/adj.dn' para log";
			exit(1);
		}

		log << setw(15) << setfill(' ')  <<
			   ip_s     << '*'  <<			//IP DE ORIGEM
			   setw(15) << setfill(' ')  <<
			   ip_d 					 <<	//IP DE DESTINO
			   endl;
	}


	static void lognet(string ip_s, unsigned hash, unsigned position, unsigned size){
		ofstream log;
		log.open("/var/www/dunadan/net.dn", ios_base::app);

		if ( !log.is_open()){
			cout << "Erro ao abrir arquivo '/var/www/dunadan/net.dn' para log";
			exit(1);
		}

		log << setw(15) << setfill(' ')  <<
			   ip_s     << '*'  <<			//IP DE ORIGEM
			   setw(15) << setfill('0') <<
			   hash     << '*' << 			//VALOR DE HASH PARA ESTE ELEMENTO
			   setw(4)  << setfill('0') <<
			   position << "*" <<    		//POSIÇÃO NA TABELA DE HASH DESTE ELEMENTO
			   size     << endl;			//TAMANHO ATUAL DA TABELA
	}

	//	Verificar testes
//	static unsigned nm_sessions;
//	static unsigned nm_adj;
//	static unsigned nm_hosts;
//	static Adjacencia* adj;
//
	static Network *net;
	static Adjacencia *adjacencia;
	static int contadorDeHosts;

	static void processor(u_char *uservar, const struct pcap_pkthdr *pheader, const u_char *packet);

private:
};


#endif /* PROCESSOR_H_ */
